'use strict'

class messageanswer{

  constructor (mdb) {
    this.mdb = mdb || null
  }

  async post(d) {
    
    let data=JSON.parse(d)
    
    try{
      
      this.mdb.connect().then(client=>{
        client.query('insert into message_answer values($1::int,$2::int,$3::int,$4::text)',[data.treeid,data.userid,data.messagecontentid,data.answer]).then(res=>{
          // return client.query('select * from message_answer where treeid=$1 and userid=$2 and messageid=$3',[data.treeid,data.userid,data.messagecontentid]);
          return 'success'
        })
      })
      
    }catch(e){
      return 'fail'
    }
  }
 
}

module.exports = messageanswer
